package com.wing.cabinet.service;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wing.cabinet.dao.StoresRequisitionProductRecordDao;
import com.wing.cabinet.model.entity.StoresRequisitionProductRecord;
import com.wing.cabinet.model.request.StoresRequisitionProductRecordForm;
import com.wing.cabinet.model.response.StoresRequisitionProductRecordVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 领新申请产品记录表-ServiceImpl
 *
 * @author
 */
@Service
@Slf4j
public class StoresRequisitionProductRecordServiceImpl extends ServiceImpl<StoresRequisitionProductRecordDao, StoresRequisitionProductRecord> implements StoresRequisitionProductRecordService {

    @Override
    public int add(StoresRequisitionProductRecordForm storesRequisitionProductRecordForm) {

        //校验

        StoresRequisitionProductRecord storesRequisitionProductRecord =new StoresRequisitionProductRecord();
        CopyOptions copyOptions = CopyOptions.create()
        .setEditable(StoresRequisitionProductRecord.class)
        .setIgnoreError(true)
        .setIgnoreNullValue(true);
        BeanUtil.copyProperties(storesRequisitionProductRecordForm, storesRequisitionProductRecord, copyOptions);

        return baseMapper.insert(storesRequisitionProductRecord);
    }

    @Override
    public List<StoresRequisitionProductRecordVO> list4app(Map<String, Object> params) {
        return baseMapper.list4app(params);
    }

    @Override
    public Page<StoresRequisitionProductRecordVO> pageList4app(Page page, Map<String, Object> params) {
        List<StoresRequisitionProductRecordVO> list = baseMapper.list4app(page, params);
        page.setRecords(list);
        return page;
    }

    @Override
    public StoresRequisitionProductRecordVO get4appById(Long id) {
        return baseMapper.get4appById(id);
    }

    @Override
    public Integer getProductNeckQuantitySum(Long requisitionProductId, String skuCode) {
        return baseMapper.getProductNeckQuantitySum(requisitionProductId,skuCode);
    }

    @Override
    public Integer sumReceivedApplyByTotalQuantity(Map<String, Object> params) {
        return baseMapper.sumReceivedApplyByTotalQuantity(params);
    }
}
